#!/bin/bash

lspci -nn |grep -i ssd &> /dev/null
if [[ $? -eq 0 ]]
  then
    mkdir -p /tmp/zabbix_ssd_monitor
    sudo /usr/local/sbin/nvme list |grep dev|awk '{print $1}' > /tmp/zabbix_ssd_monitor/nvme_list
    sed 's/$/ pcie/g' -i /tmp/zabbix_ssd_monitor/nvme_list

    length=`wc -l /tmp/zabbix_ssd_monitor/nvme_list |awk '{print $1}'`
    printf "{\n"
    printf '\t'"\"data\":["
    while read ssd_name ssd_slot
    do
        printf '\n\t\t{'
        printf "\"{#SSD_NAME}\":\"${ssd_name}\",\"{#SSD_SLOT}\":\"${ssd_slot}\"}"
        length=$(($length-1))
        if [ $length -gt 0 ]
        then
            printf ','
        fi
    done < /tmp/zabbix_ssd_monitor/nvme_list 
    printf "\n\t]\n"
    printf "}\n"
fi
rm -rf /tmp/zabbix_ssd_monitor

#sudo nvme smart-log /dev/nvme0n1
#sudo nvme intel smart-log-add /dev/nvme0n1